package cc.jq1024.domain.activity.service.quota.policy.impl;

import cc.jq1024.domain.activity.model.aggregate.CreateQuotaOrderAggregate;
import cc.jq1024.domain.activity.model.valobj.OrderStateVO;
import cc.jq1024.domain.activity.repository.IActivityRepository;
import cc.jq1024.domain.activity.service.quota.policy.ITradePolicy;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 返利奖励【无需支付类交易】
 * @author li--jiaqiang
 * @date 2024−07−17
 */
@Slf4j
@Service("rebate_no_pay_trade")
@RequiredArgsConstructor
public class RebateNoPayTradePolicy implements ITradePolicy {

    private final IActivityRepository activityRepository;

    /**
     * 交易（下单）接口 - 【无需进行支付】
     * @param createQuotaOrderAggregate 订单聚合对象
     */
    @Override
    public void trade(CreateQuotaOrderAggregate createQuotaOrderAggregate) {
        // 不需要支付则修改订单金额为0，状态为完成，直接给用户账户充值
        createQuotaOrderAggregate.setOrderState(OrderStateVO.completed);
        createQuotaOrderAggregate.getActivityOrderEntity().setPayAmount(BigDecimal.ZERO);
        activityRepository.doSaveNoPayOrder(createQuotaOrderAggregate);
    }
}